<template>
  <div class="switch-container">
    <div class="box">
      <div
        class="box-item"
        v-for="(item, index) in list"
        :key="item.name"
        @click="handleSelected(index)"
        :class="{ active: selectId === index }"
      >
        {{ item.name }}
        <!-- :style="{ color: selectId === index ? '#ff5f16' : '#333'}" -->
      </div>
    </div>
  </div>
</template>
<script setup>
import { ref } from "vue";
const selectId = ref(0);

const handleSelected = (e) => {
  selectId.value = e;
};
const list = ref([{ name: "推荐" }, { name: "距离" }]);
</script>
<style lang="scss">
.switch-container {
  .box {
    display: flex;
    align-items: center;
    background-color: #fff;
    // padding: 20px;
    padding: 5px;
    border-radius: 70px;
    font-size: 22px;
    .box-item {
      padding: 10px 25px;
      border-radius: 70px;
    }
  }
  .active {
    background-color: #ff5f16;
    color: #fff;
    transition: background-color 0.3s ease-in-out;
  }
}
</style>
